package com.yicong.ants.view;

import android.content.Context;
import androidx.databinding.DataBindingUtil;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.yicong.ants.R;
import com.yicong.ants.databinding.PayFieldBinding;

/**
 * @author cchao
 * @version 2019-05-28.
 */
public class PayMethodView extends LinearLayout implements View.OnClickListener {
    PayFieldBinding mBinding;
    int mCurSelect = 0;

    public PayMethodView(Context context) {
        this(context, null);
    }

    public PayMethodView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.pay_field, this, true);
        mBinding.setClick2(this);
    }

    void paySelect(int index) {
        mCurSelect = index;
        mBinding.radioWx.setChecked(index == 0);
        mBinding.radioAli.setChecked(index == 1);
    }

    int getSelect() {
        return mCurSelect;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.pay_wx_field:
                paySelect(0);
                break;
            case R.id.pay_ali_field:
                paySelect(1);
                break;
        }
    }
}
